<?php

namespace console\controllers;

use common\models\IcoOrder;
use common\service\transaction\Eth;
use Yii;
use yii\console\Controller;

class OrderController extends Controller
{
    /**
     * 更新订单状态
     */
    public function actionUpdate()
    {
        $orders = IcoOrder::findAll(['status'=>[
            IcoOrder::STATUS_NOT_PAY,
            IcoOrder::STATUS_PAY_ING
        ]]);
        foreach( $orders as $order )
        {
            echo $order->trade_no . "\n";
            list($tradeStatus,$money) = Eth::getTransStatus( $order->trade_no );
            echo $tradeStatus . "\n";
            switch( $tradeStatus )
            {
                case Eth::STATUS_ING:
                    break;
                case Eth::STATUS_COMPLETE:
                    $order->status = IcoOrder::STATUS_NEED_OK;
                    $order->money = $money;
                    $order->save();
                    break;
                case Eth::STATUS_FAILED:
                    break;
                case Eth::STATUS_NOT_EXIST:
                    break;
            }
            sleep(0.1);
        }
    }
}
